<html>
	<head>
		<meta charset="UTF-8">
		<title>下游组织管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">
				
				<!--标题栏-->
				<p class="content_title">账号管理 &nbsp;&nbsp;>&nbsp;&nbsp;下游组织管理</p>
				<!--标题栏-->
				
				<!--条件查询-->
				<div class="content_seach">
					<div class="layui-form">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label w50">用户名</label>
								<div class="layui-input-inline">
									<input type="text" name="userAccount" id="userAccount" placeholder="请输入用户名" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label w50">组织名称</label>
								<div class="layui-input-inline">
									<input type="text" name="userCompanyAllTitle" id="userCompanyAllTitle" placeholder="请输入下游组织名称" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label w50">联系方式</label>
								<div class="layui-input-inline">
									<input type="text" name="linkmanPhone" id="linkmanPhone" placeholder="请输入联系方式" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label w50">创建时间</label>
								<div class="layui-input-inline">
									<input type="text" name="createDate" id="dateStart" placeholder="请选择时间" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid">至</div>
								<!-- <label class="layui-form-label w50">至</label> -->
								<div class="layui-input-inline">
									<input type="text" name="createDate" id="dateEnd" placeholder="请选择时间" autocomplete="off" class="layui-input">
								</div>
							</div>
							<br/>
							<div class="layui-inline">
								<label class="layui-form-label w50">关联站点</label>
								<div class="layui-input-inline">
									<input type="text" name="siteids" id="siteids" placeholder="请输入关联站点" autocomplete="off" class="layui-input">
								</div>
							</div>
							<button class="layui-btn layui-btn-warm search layui-btn-sm" id="search" lay-submit=""  lay-filter="search"><i class="layui-icon">&#xe615;</i>查询</button>
						</div>
					</div>
				</div>
				<!--条件查询-->
				
				<!--表格-->
				<div class="content_table">
					<script type="text/html" id="toolbarDemo">
						<div class="layui-btn-container">
							<a href="./downstreamAdd.html?pos=5&childPos=1" class="layui-btn layui-btn-sm">
								<i class="layui-icon">&#xe654;</i> 添加
							</a>
						</div>
					</script>
					<div class="tabTable">
						<table id="table" lay-filter="tableFilter"></table>
						<div class="layui-table-page fr">
							<div id="layui-table-page1"></div>
						</div>
					</div>
				</div>
				<!--表格-->
			</div>
			
		</div>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<!--操作-->
		<script type="text/html" id="toolbarOperation">
			<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
			<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
		</script>
		<!--账号状态自定义模板-->
		<script type="text/html" id="userStatusTemplet">
			{{#if (d.userStatus == 0) { }}
				正常
			{{# }else if(d.userStatus == 1){ }}
				禁用
			{{# } }}
		</script>
		<!--创建时间自定义模板-->
		<script type="text/html" id="createDateTemplet">
			{{d.createDate.split(".")[0]}}
		</script>
		<script>
			layui.use(['table', 'laydate','laytpl'], function(){
				var table = layui.table,form = layui.form,laydate = layui.laydate,laytpl = layui.laytpl;
				
				//创建时间
				laydate.render({
					elem: '#dateStart'
				});
				laydate.render({
					elem: '#dateEnd'
				});
				
				//列表渲染
				ajaxTable({
					idNode: '#table',
					url:'user/getList',
					urlParme:'&userType=2',//用户类型 0admin甲方 1燃气公司账号 2下游账号 3普通用户
					dataCols:[ 
						{fixed: true,checkbox: true,height: 180,align: 'center'},
						{field: 'id',title: '序号',width: 100,align: 'center',sort: true}, 
						{field: 'userAccount',title: '用户名',align: 'center'},
						{field: 'userCompanyAllTitle',title: '下游组织名称',align: 'center'}, 
						{field: 'linkmanName',title: '联系人',align: 'center'}, 
						{field: 'linkmanPhone',title: '联系方式',align: 'center'},
						{field: 'siteids',title: '关联站点',align: 'center'},
						{field: 'userStatus',title: '账户状态',align: 'center',templet: '#userStatusTemplet'}, 
						{field: 'createDate',title: '创建时间',align: 'center',templet: '#createDateTemplet',sort: true}, 
						{field: 'right', title: '操作', toolbar:"#toolbarOperation",align: 'center'}
					],
					done:function(res){
					    table_data=res.data;
					}
				});
				
				//条件查询
				form.on('submit(search)', function(data){
					var userAccount=$("#userAccount").val(),userCompanyAllTitle=$("#userCompanyAllTitle").val(),
					linkmanPhone=$("#linkmanPhone").val(),siteids=$("#siteids").val(),
					dateStart=$("#dateStart").val(),dateEnd=$("#dateEnd").val();
					//+"&createDate="+dateStart+"&createDate="+dateEnd
					ajaxTable({
						idNode: '#table',
						type: "GET",
						url: "user/getList",
						urlParme: "&userType=2&userAccount="+userAccount+"&userCompanyAllTitle="+userCompanyAllTitle+"&linkmanPhone="+linkmanPhone+"&siteids="+siteids,
						dataCols:[ 
							{fixed: true,checkbox: true,height: 180,align: 'center'},
							{field: 'id',title: '序号',align: 'center',sort: true}, 
							{field: 'userAccount',title: '用户名',align: 'center'},
							{field: 'userCompanyAllTitle',title: '下游组织名称',align: 'center'}, 
							{field: 'linkmanName',title: '联系人',align: 'center'}, 
							{field: 'linkmanPhone',title: '联系方式',align: 'center'},
							{field: 'siteids',title: '关联站点',align: 'center'},
							{field: 'userStatus',title: '账户状态',align: 'center',templet: '#userStatusTemplet'}, 
							{field: 'createDate',title: '创建时间',align: 'center',templet: '#createDateTemplet',sort: true}, 
							{field: 'right', title: '操作', toolbar:"#toolbarOperation",align: 'center'}
						],
						successFull: function (res, curr, count) {
							console.log(res)
						}
					});
				});
				
				//监听工具条
				table.on('tool(tableFilter)', function(obj){
					var data = obj.data;
					if(obj.event === 'detail'){
						
						$.ajax({
							url: baseUrl+"/user/getById?id="+data.id,
							type: "GET",
							success: function(data){
								console.log(data);
								var statusDesc;
								if(data.userStatus==0){
									statusDesc='正常';
								}else if(data.userStatus==1){
									statusDesc='禁用';
								}else{
									statusDesc='无状态';
								}
						
								//弹出用户信息
								layer.open({
									type: 1,
									title: false, //不显示标题栏
									closeBtn: true,
									area: '300px;',
									shade: 0.5,
									id: 'LAY_layuipro', //设定一个id，防止重复弹出
									btnAlign: 'c',
									moveType: 1, //拖拽模式，0或者1
									content: '<div style="padding: 50px; line-height: 40px; background-color: #f9f9fb; color: #black; font-weight: 400;height: 200px;">'+
												  '<p>用户名：'+data.userAccount+'</p>'+
												  '<p>公司简称：'+data.userCompany+'</p>'+
												  '<p>公司简称：'+data.userCompany+'</p>'+
												  '<p>账号状态：'+statusDesc+'</p>'+
												  '<p>联系人：'+data.linkmanName+'</p>'+
												  '<p>联系电话：'+data.linkmanPhone+'</p>'+
												  '<p>邮箱：'+data.userEmail+'</p>'+
												  '<p>创建时间：'+data.createDate+'</p>'+
												  '<p>描述：'+data.userDesc+'</p>'+
											 '</div>',
									success: function(layero){
										var btn = layero.find('.layui-layer-btn');
										btn.find('.layui-layer-btn0').attr({
										href: 'http://www.layui.com/'
										,target: '_blank'
										});
									}
								});
							}
						});
					} else if(obj.event === 'del'){
						layer.confirm('确定删除吗？', function(index){
							console.log(data);
							$.ajax({
								url: baseUrl+"/user/del",
								type: "POST",
								data:{"id":data.id},
								dataType: "json",
								success: function(data){
									if(data.code==200){
										obj.del();
										layer.close(index);
										layer.msg("删除成功", {icon: 6});
									}else{
										layer.msg("删除失败", {icon: 5});
									}
								}
							});
						});
					} else if(obj.event === 'edit'){
						layer.confirm('确定修改吗？', function(index){
							location.href="./downstreamEdit.html?pos=5&childPos=1&id="+data.id;
						});
					}
				});
				
			});
		</script>
				
	</body>
</html>